package Pipe;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * 过滤器，设计为实现写入新文字“Welcome to Chengdu”
 * @author fengke
 */
public class AddLine extends Filter{

    /**
     * 输入文件的文件名
     */
    private File infile;
    AddLine(File file, Pipe output){
        super(null, output);
        this.infile = file;
    }

    @Override
    /**
     * 读取数据
     * 以行为单位读取
     */
    protected void transform() throws IOException {
        Scanner sc = new Scanner(infile);
        String templine = "";
        while(sc.hasNextLine()){
            templine = sc.nextLine();
            System.out.println("Input:" + templine);
            output.writerLine(templine);
        }
        output.writerLine("welcome to chengdu");
        output.closeWriter();
        sc.close();
    }
}

